
#include <game_state/pause/pause_game_state.hpp>
#include <resource_cache/resource_cache.hpp>
#include <input/inputSingleton.h>
#include <input/actions/actions.hpp>
#include <SFML/Window.hpp>
#include <window/window.hpp>

pause_game_state::pause_game_state( game_state_ptr previous_state )
	:		m_previous_state( previous_state )
{
	g_user_input.removeAction( actions::pause );
	g_user_input.assignActionToKey( actions::pause, sf::Key::P );

	float const pos = ( 800.0f - 256.0f ) * 0.5f;

	sf::Image * pause_image = g_cache.load_image( "./resources/images/pause/Pause.tga" );

	m_sprite.SetPosition( pos, pos );
	m_sprite.SetImage( *pause_image );
	m_sprite.SetBlendMode( sf::Blend::Alpha );
}

game_state_ptr pause_game_state::step( float /*delta_time*/ )
{
	if ( g_user_input.getActionInput( actions::pause ).status == keyPressed )
	{
		return m_previous_state;
	}
	else
	{
		return shared_from_this( );
	}
}

void pause_game_state::draw( )
{
	m_previous_state->draw( );

	g_window->Draw( m_sprite );
}
